import 'package:digital/pages/tab/index.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class TabPage extends StatefulWidget {
  const TabPage({super.key});

  @override
  State<TabPage> createState() => TabPageState();
}

class TabPageState extends State<TabPage> {
  int tabIndex = 1;
  GlobalKey moreKey = GlobalKey();
  PageController pageController = PageController();

  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    super.dispose();
    pageController.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: _buildPageView(),
      bottomNavigationBar: _buildNavigationBar(),
    );
  }

  _buildPageView(){
    return PageView.builder(
      itemCount: 3,
      physics: const NeverScrollableScrollPhysics(),
      controller: pageController,
      itemBuilder: (context, index){
        print("------$index");
        if (index == 0){
          return const IndexPage();
        }
        else if(index==1){
          return const IndexPage();
        }
        else{
          return const IndexPage();
        }
      }
    );
  }

  _buildNavigationBar(){
    return BottomNavigationBar(
      selectedFontSize: 10.w,
      unselectedFontSize: 10.w,
      selectedItemColor: const Color(0xFF1296db),
      unselectedItemColor: const Color(0xFF8a8a8a),
      backgroundColor: Colors.white,
      showUnselectedLabels:true,
      type: BottomNavigationBarType.fixed,
      currentIndex: tabIndex,
      onTap: (index){
        pageController.jumpToPage(index);
        setState((){
          tabIndex = index;
        });
      },
      items: [
        BottomNavigationBarItem(
          icon: tabIconItem("assets/tabBar/icon1.png"),
          activeIcon: tabIconItem("assets/tabBar/icon1.png"),
          label: "首页",
        ),
        BottomNavigationBarItem(
          icon: tabIconItem("assets/tabBar/icon2.png"),
          activeIcon: tabIconItem("assets/tabBar/icon2_active.png"),
          label: "聊天",
        ),
        BottomNavigationBarItem(
          icon: tabIconItem("assets/tabBar/icon3.png"),
          activeIcon: tabIconItem("assets/tabBar/icon3.png"),
          label: "我的",
        ),
      ],
    );
  }

  tabIconItem(String icon){
    return Padding(
      padding: EdgeInsets.only(bottom: 4.w),
      child: Image.asset(icon ,width: 22.w,height: 22.w),
    );
  }

}



